home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_pru_jagattack.cog < prev    next >
Text File  |  1999-11-15  |  7KB  |  316 lines

  1. # Jones 3D Cog Script
  2. #
  3. # PRU_snakehole.cog    Snake comes out of hole if Indy approaches.
  4. #
  5. # [GGJ]
  6. #
  7. # (C) 1999 LucasArts Entertainment Company LLC. All Rights Reserved
  8. #
  9. # ========================================================================================
  10. symbols
  11.  
  12. message entered
  13. message    startup
  14. message    aievent
  15. message sighted
  16. message    arrivedwpnt
  17. message timer
  18. message updatewpnts
  19.  
  20. thing    jag
  21. thing    jagTarget
  22. thing    player        local
  23. sector    lookSector    
  24. sector    downRiverSector
  25.  
  26. int        n_eventType        local
  27. int        n_CrntAIMode     local
  28. int        n_OldAIMode     local
  29. int        n_Waypoint        local
  30. int        b_HideOnEndFleeMode = 0 local
  31. int        n_Temp            local
  32. int        b_Temp            local
  33. flex    f_Temp            local
  34. int        n_TimerID        local 
  35. int        n_idx            local
  36. int        numAttacks=0    local
  37.  
  38. flex    initwaypoints            local
  39. flex    rankWaypointsForFlee    local
  40. flex    ResetWaypointRanks        local
  41.  
  42.  
  43.  
  44. vector    v_IndyPos        local
  45. vector    v_JagPos        local
  46. vector    v_JagToIndy        local
  47. vector    v_IndyLook        local
  48.  
  49. flex    f_HideTime        local
  50.  
  51. # ===========================FLEE WAYPOINTS================================================
  52. int            NUM_FLEE_WAYPOINTS=15            local
  53. int            FINAL_FLEE_WAYPOINT=14            local
  54. thing        t_Waypoint00
  55. thing        t_Waypoint01
  56. thing        t_Waypoint02
  57. thing        t_Waypoint03
  58. thing        t_Waypoint04
  59. thing        t_Waypoint05
  60. thing        t_Waypoint06
  61. thing        t_Waypoint07
  62. thing        t_Waypoint08
  63. thing        t_Waypoint09
  64. thing        t_Waypoint10
  65. thing        t_Waypoint11
  66. thing        t_Waypoint12
  67. thing        t_Waypoint13
  68. thing        t_Waypoint14
  69.  
  70. # ===========================MISC CONSTANTS================================================
  71.  
  72. flex    MIN_INITIAL_HIDE_TIME=5.0        local
  73. flex    VARIABLE_INITIAL_HIDE_TIME=5.0    local
  74. flex    RETRY_HIDE_TIME=5.0             local
  75.  
  76. int        TIMER_ID_WAKE_UP=0                local
  77.  
  78.  
  79. surface    triggerSurf
  80.  
  81. int    jagJumpStarted=0            local
  82. int    jagJumpFinished=0            local
  83.  
  84. end
  85. # ========================================================================================
  86.  
  87. code
  88. startup:
  89.     #10000 causes ai to send event messages, 2000 is disabling, 40 is "don't look for cliff"
  90.     #AISetMode(jag, 0x12040);
  91.     AISetCutsceneMode(jag);
  92.     player=GetLocalPlayerThing();
  93. //    ClearThingFlags(jag, 0x100000);
  94.  
  95.     AISetMode(jag, 0x40000);        # Add SITHAI_MODEINSTINCTUSEWPNTS to jaguar's AI mode 
  96.  
  97.     call InitWaypoints;
  98.     return;
  99.  
  100. # ========================================================================================
  101. entered:
  102.     if (GetSenderRef() == downRiverSector)
  103.     {
  104.         numAttacks = 5;
  105.         AISetMode(jag, 0x2000);
  106.         return;
  107.     }
  108.  
  109.     if (!jagJumpStarted)
  110.     {
  111.         jagJumpStarted=1;
  112.         AISetLookThing(jag, jagTarget);
  113.         AISetMoveSpeed(jag, 1.0);
  114.         AISetMoveThing(jag, jagTarget, 1.9);
  115.     }
  116.     return;
  117.  
  118. # ========================================================================================
  119. aievent:
  120.     n_eventType        = GetParam(0);
  121.     n_CrntAIMode    = GetParam(1);
  122.     n_OldAIMode        = GetParam(2);    // only valid for certain n_eventType values
  123.  
  124.     if (n_eventType == 0x100)        // SITHAI_EVENTMODECHANGED
  125.     {
  126.         // if changing to flee mode
  127.         // turn on waypoints
  128.         if ( !BITTEST(n_OldAIMode, 0x800) && BITTEST(n_CrntAIMode, 0x800) )
  129.         {
  130.             AISetSubMode(jag, 0x8000); // SITHAI_SUBMODECONTINUOUSWPNTMOTION
  131.             call RankWaypointsForFlee;
  132.         }
  133.         // if exiting flee mode
  134.         // turn off waypoints
  135.         else if ( BITTEST(n_OldAIMode, 0x800) && !BITTEST(n_CrntAIMode, 0x800) )
  136.         {
  137.             if (b_HideOnEndFleeMode)
  138.             {
  139.                 SetThingFlags(jag, 0x80000); // disable (i.e. hide)
  140.                 f_HideTime = (MIN_INITIAL_HIDE_TIME + (Rand() * VARIABLE_INITIAL_HIDE_TIME));
  141.                 SetTimerEx(f_HideTime , TIMER_ID_WAKE_UP, 0, 0 );
  142.                 b_HideOnEndFleeMode = 0;
  143.             }
  144.             AIClearSubMode(jag, 0x8000); // SITHAI_SUBMODECONTINUOUSWPNTMOTION
  145.             call ResetWaypointRanks;
  146.         }
  147.     }
  148.     #check to see that the jag is approaching his target
  149.     else if (n_eventType == 0x2000)
  150.     {
  151.         if (!jagJumpFinished)
  152.         {
  153.             #AIClearMode(jag, 0x12040);
  154.             AIClearCutsceneMode(jag);
  155.             //        AISetFireTarget(jag, player);
  156.             #set ai to active and attacking
  157.             #AISetMode(jag, 0x202);
  158.             jagJumpFinished = 1;
  159.         }
  160.     }
  161.  
  162. return;
  163.  
  164. # ========================================================================================
  165. timer:
  166.     player = GetLocalPlayerThing();
  167.     
  168.     n_TimerID = GetSenderID();
  169.     if (n_TimerID == TIMER_ID_WAKE_UP)
  170.     {
  171.         
  172.         if (numAttacks > 4) return;                                #Geoff added to prevent Jag from attacking forever.
  173.         numAttacks = numAttacks + 1;
  174.         
  175.         
  176.         v_IndyPos = GetThingPos(player);
  177.         v_JagPos = GetThingPos(jag);
  178.         v_JagToIndy = VectorNorm(VectorSub(v_IndyPos, v_JagPos));
  179.         v_IndyLook = GetThingLVec(player);
  180.  
  181.         f_Temp = VectorDot(v_JagToIndy, v_IndyLook);
  182.  
  183.         // If indy is facing the other way, then come out of hiding
  184.         if (f_Temp >= 0.0)
  185.         {
  186.             ClearThingFlags(jag, 0x80000); // enable
  187. //            ClearActorFlags(jag, 0x800); // turn off blindness
  188.             AIWpntHuntTarget(jag, 0.55, 0.0);
  189.         }
  190.         // Otherwise try again in a few seconds
  191.         else
  192.         {
  193.             SetTimerEx(RETRY_HIDE_TIME , TIMER_ID_WAKE_UP, 0, 0 );
  194.         }
  195.     }
  196.  
  197.     return;
  198.  
  199.  
  200. # ========================================================================================
  201. sighted:
  202.     if (GetSenderRef() != lookSector) return;
  203.     
  204.     if (!jagJumpStarted)
  205.     {
  206.         jagJumpStarted = 1;
  207.         Sleep(RandBetween(2, 4));
  208.         AISetLookThing(jag, jagTarget);
  209.         AISetMoveSpeed(jag, 1.0);
  210.         AISetMoveThing(jag, jagTarget, 1.9);
  211.     }
  212.  
  213.     return;
  214.  
  215.  
  216. # ========================================================================================
  217. arrivedwpnt:
  218.     n_Waypoint = GetParam(0);
  219.  
  220.     // If arrived at final waypoint during flee, then go into hiding
  221.     if ( (n_Waypoint == FINAL_FLEE_WAYPOINT) && BITTEST(AIGetMode(jag), 0x800))
  222.     {    
  223.         // So flee will end 
  224.         //     jag must not be able to see player
  225.         //    clear continuous bit will prevent flee from advancing
  226. //        SetActorFlags(jag, 0x800); // blind 
  227. //        AIClearSubMode(jag, 0x8000); // SITHAI_SUBMODECONTINUOUSWPNTMOTION
  228.         b_HideOnEndFleeMode = 1;
  229.         AIStopFlee(jag);
  230.         StopThing(jag);
  231.     }
  232.  
  233.     return;
  234.  
  235. updatewpnts:
  236.     return;
  237.  
  238. # ========================================================================================
  239. InitWaypoints:
  240.  
  241.  
  242.     for ( n_idx = 0; n_idx < NUM_FLEE_WAYPOINTS; n_idx = n_idx + 1 )
  243.     {
  244.         AISetWpnt(t_Waypoint00[n_idx], n_idx);
  245.     }
  246.  
  247.     AIConnectWpnts(0, 1);
  248.     AIConnectWpnts(0, 2);
  249.     AIConnectWpnts(1, 2);
  250.     AIConnectWpnts(1, 3);
  251.     AIConnectWpnts(1, 4);
  252.     AIConnectWpnts(1, 5);
  253.     AIConnectWpnts(2, 4);
  254.     AIConnectWpnts(2, 5);
  255.     AIConnectWpnts(2, 6);
  256.     AIConnectWpnts(3, 4);
  257.     AIConnectWpnts(3, 7);
  258.     AIConnectWpnts(4, 5);
  259.     AIConnectWpnts(4, 7);
  260.     AIConnectWpnts(5, 6);
  261.     AIConnectWpnts(5, 8);
  262.     AIConnectWpnts(6, 10);
  263.     AIConnectWpnts(7, 8);
  264.     AIConnectWpnts(7, 9);
  265.     AIConnectWpnts(8, 10);
  266.     AIConnectWpnts(9, 10);
  267.     AIConnectWpnts(9, 11);
  268.     AIConnectWpnts(10, 12);
  269.     AIConnectWpnts(11, 12);
  270.     AIConnectWpnts(11, 13);
  271.     AIConnectWpnts(12, 13);
  272.     AIConnectWpnts(13, 14);
  273.  
  274.     return;
  275.  
  276.  
  277.     
  278. RankWaypointsForFlee:
  279.     
  280.     AISetWpntRank(0, 0);
  281.  
  282.     AISetWpntRank(1, 5);
  283.     AISetWpntRank(2, 5);
  284.  
  285.     AISetWpntRank(3, 10);
  286.     AISetWpntRank(4, 10);
  287.     AISetWpntRank(5, 10);
  288.     AISetWpntRank(6, 10);
  289.  
  290.     AISetWpntRank(7, 15);
  291.     AISetWpntRank(8, 15);
  292.  
  293.     AISetWpntRank(9, 20);
  294.     AISetWpntRank(10, 20);
  295.  
  296.     AISetWpntRank(11, 25);
  297.     AISetWpntRank(12, 25);
  298.  
  299.     AISetWpntRank(13, 30);
  300.     AISetWpntRank(14, 35);
  301.  
  302.     return;
  303.  
  304.  
  305. ResetWaypointRanks:
  306.  
  307.     for ( n_idx = 0; n_idx < NUM_FLEE_WAYPOINTS; n_idx = n_idx + 1 )
  308.     {
  309.         AISetWpntRank(n_idx, 0);
  310.     }
  311.  
  312.     return;
  313.  
  314. end
  315.        
  316.